package com.baize.cpdepus.controller;

import com.baize.cpdepus.common.R;
import com.baize.cpdepus.entity.Category;
import com.baize.cpdepus.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//类别添加和删除只有管理员与维护人员可以访问 后面编写中添加权限
@RequestMapping("/category")
@RestController
@Slf4j
@CrossOrigin  //跨域
@Api(value = "类别操作",tags = "类别操作接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @DeleteMapping("remove")
    @ApiOperation(value = "删除分类")
    private R<String> remove(
            @ApiParam(value = "分类ID", required = true)
            Integer ID) {
        categoryService.remove(ID);
        return R.success("删除成功");
    }

    @GetMapping("getAll")
    @ApiOperation(value = "获取所有分类")
    public R<List<Category>> getAll() {
        List<Category> categories = categoryService.SelectAll();
        return R.success(categories);
    }
}
